application_fack_data=[
		{	empid:'AE1856',
			name:'何宇林',
			create_time:'2016-01-12',
			category:'annual_leave',
			start_time:'2016-01-11 08:30',
			end_time:'2016-01-11 17:51',
			check_record:[
					{	name:'哈哈',
						status:'approved',
						time:'2013-34-21',
						note:'我的备注'
					},
        			{	name:'大王',
        				status:'pending',
        				time:'23412-5215',
        				note:''
        			},
        			{	name:'哈哈',
        				status:'approved',
        				time:'2013-34-21',
        				note:'我的备注'
        			},
        			{	name:'大王',
        				status:'pending',
        				time:'23412-5215',
        				note:'sdfsf'
        			}],
        	status:'approved',
        	note:'08:30'
       },
       {	empid:'AE1857',
       		name:'白联军',
       		create_time:'2016-01-11',
       		category:'sick_leave',
       		start_time:'2016-08-30 17:52',
       		end_time:'2016-01-11 17:51',
       		check_record:[
       			{	name:'哈哈',
	       			status:'approved',
	       			time:'2013-34-21',
	       			note:'我的备注'
       			},
        		{	name:'大王',
		    		status:'pending',
		    		time:'23412-5215',
		    		note:'sdfsf'
		    	}],
        	status:'rejected',
        	note:'08:30'
       }]


app.controller('application_controller',function ($scope,$http,headFilterManager) {
	$scope.fb={
		show:{
			keywords:true
		}
	}

	$scope.heads=[	{name:'empid',label:'员工号',order:'+',filter:true},
					{name:'name',label:'姓名',order:'+',filter:true},
					{name:'create_time',label:'提交日期',order:'+',filter:true},
					{name:'category',label:'请假种类',order:'+',filter:true},
					{name:'start_time',label:'开始时间',order:'+',editor:'text',filter:true},
					{name:'end_time',label:'结束时间',order:'+',editor:'text',filter:true},
					{name:'progress',label:'进度',editor:'text'},
					{name:'status',label:'状态',order:'+',editor:'text',filter:true},
					{name:'note',label:'备注',editor:'text'},
					]
	$scope.uploading=false;
	$scope.currentPage=0;
	$scope.itemsPerPage=20;
	 if(is_local){
        $scope.org_records=application_fack_data  
	}else{
		$scope.org_records=[]
	}
	$scope.records=$scope.org_records;
	// -----------为了头部过滤------------
	var hfmanagr=new headFilterManager.HFManager()
	hfmanagr.initHeads($scope.heads)
	$scope.$on('head_filter_changed',function (even,filter) {
		if(hfmanagr.has_filter(filter)){
			//$scope.records=$scope.funlist_filter($scope.org_records)
			$scope.records=hfmanagr.filter($scope.org_records)
		}
	})
	//-某个头部排序，通知其他排序变为'不排序'
	$scope.$on('sortClick',function (even,name) {
		$scope.$broadcast('otherSortClick',name);
	})
	//------------------------
	$scope.search=function (start_date,end_date,fb) {
			var post_data = {
					hr_leave_record:{start_date:start_date,
									end_date:end_date,keyword:fb.keywords
									},
				};  
			$scope.fb.uploading=true;
			$http.post(post_url,post_data)
			.success(function(data, status, headers, config) { 
				$scope.org_records=data.hr_leave_record.leaves;
				$scope.records=$scope.org_records
				$scope.fb.uploading=false;
			}).error(function(data, status, headers, config) {  
			    alert('有错误,返回码为:'+status)
			    $scope.fb.uploading=false;
			});
		}
		
	$scope.update_to_server=function () {
		var records=$scope.records;
		var postlist=[];
		for(x in records){
			if(records[x].dirty){
				postlist.push(records[x])
			}
		}
		
		var post_data = {
			update_application:{records:postlist},
			}; 
		$scope.uploading=true;
		$http.post(post_url,post_data)
		.success(function(data, status, headers, config) { 
			$scope.uploading=false;
			var updatedlist=data.update_application.records;
			var old_records=$scope.org_records;
			for (x in updatedlist){
				for(y in old_records){
					if(old_records[y].id==updatedlist[x].id){
						old_records[y]=updatedlist[x];
						break;
					}
				}
			}
			$scope.$broadcast('arrayUpdated',$scope.org_records)
			//on_org_records_update()
		}).error(function(data, status, headers, config) {  
		    //处理错误 
		    $scope.std='有错误,返回码为:'+status;
		});
	}
})